package com.sun.alen.mapper;

import com.sun.alen.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {
    @Insert("INSERT INTO course (courseName, courseSemester, courseCreditHour,teacherId,professionId) " +
            "VALUES (#{courseName}, #{courseSemester},#{courseCreditHour} ,#{teacherId},#{professionId})")
    boolean add(Course course);

    @Delete("DELETE FROM course WHERE courseId=#{id}")
    boolean delete(String id);

    @Update("UPDATE course SET courseName=#{courseName}, courseSemester=#{courseSemester},courseCreditHour=#{courseCreditHour}, teacherId=#{teacherId} ,professionId=#{professionId} " +
            "WHERE courseId=#{courseId}")
    boolean update(Course course);

    @Select("select * from course limit #{start},#{pageSize}")
    List<Course> list(Integer start, Integer pageSize);

    @Select("select count(*) from course")
    long count();

    @Select("select * from course where courseName like #{input} limit #{start},#{pageSize}")
    List<Course> searchByName(String input, Integer start, Integer pageSize);

    @Select("select count(*) from course where courseName like #{input}")
    long countByName(String input);

    @Select("select * from course where professionId =#{id}")
    List<Course> searchByProfession(Integer id);

    @Select("select * from course where teacherId =#{teacherId}")
    List<Course> searchByTeacher(int teacherId);

    @Select("SELECT * from course where courseName like #{input}")
    List<Course> searchIdByStudent(String input);

    @Select("select * from course")
    List<Course> all();

    @Select("select * from course where teacherId=#{teacherId} and courseName like #{input} limit #{start},#{pageSize}")
    List<Course> searchByCourseName(String input, Integer teacherId, Integer start, Integer pageSize);

    @Select("select count(*) from course where teacherId=#{teacherId} and courseName like #{input} ")
    long countByCourseName(String input, Integer teacherId);

    @Select("select * from course where courseName like #{input}")
    List<Course> searchAllByCourseName(String input);
}
